Intro to Crypto 3 - localo

Category: Crypto
Difficulty: Baby
Author: black-simon

Description

This is an introductory challenge for beginners which want to dive into the world of Cryptography. The three stages of this challenge will increase in difficulty.

After a new potentially deadly disease first occurring in Wuhan, China, the Chinese Corona Response Team sends messages to the remainder of the world. However, to avoid disturbing the population, they send out this message encrypted.

We have intercepted all messages sent by the Chinese government and provide you with the public keys found on the governments' website.

Please, find out if we are all going to die!

Summery

The author provided a intercepted-messages.txt and three .pem files.
The intercepted-messages.txt contains three numbers and the .pem files contains three public keys. All we have to do is to decrypt the messages.

Solution

Since e is 3 in all public keys and we have three message-key pairs, we can use the Håstad's_broadcast_attack Wikipedia

import OpenSSL.crypto as crypto
from factordb.factordb import FactorDB

def read_key(f):
    return crypto.load_publickey(crypto.FILETYPE_PEM,open(f,"rb").read()).to_cryptography_key().public_numbers()

keyD = read_key("german_government.pem")
keyU =  read_key("us_government.pem")
keyR = read_key("russian_government.pem")

messages = [int(l.split(": ")[1]) for l in open("intercepted-messages.txt","rb").readlines()]

cD = messages[0]
cU = messages[1]
cR = messages[2]

assert(keyD.e==keyU.e==keyR.e==3)

M = crt([cD,cU,cR],[keyD.n,keyU.n,keyR.n]).nth_root(3)
print(hex(int(str(M))).replace("L","")[2:].decode('hex'))

Mitigation

Flag

CSCG{ch1nes3_g0vernm3nt_h4s_n0_pr0blem_w1th_c0ron4}